import blogModule from "@/modules/blog";
import { NextResponse } from "next/server";

export async function GET(request) {
  const { searchParams } = new URL(request.url);
  const limit = searchParams.get("limit") || 10;
  const page = searchParams.get("page") || 1;
  const offset = (Number(page) - 1) * limit;
  const blogsData = await blogModule.getAll(Number(limit), offset);
  if (!blogsData) { return NextResponse.json({ message: "No blogs found" }, { status: 404 })};
  return NextResponse.json({message: "Blogs fetched successfully", blogs:blogsData.blogs, total: blogsData.total}, { status: 200 });
}